#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 1e6+5;
int n;
ll a[N];
int main(){
    freopen("color.in", "r", stdin);
    freopen("color.out", "w", stdout);
    int T;
    cin >> T;
    while(T--){
        scanf("%d", &n);
        for(int i = 1; i <= n; i++){
            scanf("%lld", &a[i]);
        }
        if(n > 100){
            printf("0\n");
            continue;
        }
        ll ans = 0, maxans = 0;
        for(int i = 0; i <= (1<<n)-1; i++){
            ans = 0;
            for(int j = 0; j < n; j++){
                for(int k = j-1; k >= 0; k--){
                    if((i>>j)%2 == (i>>k)%2){
                        if(a[j+1] == a[k+1]) ans += a[j+1];
                        break;
                    }
                }
            }
            maxans = max(maxans, ans);
        }
        printf("%lld\n", maxans);
    }
    return 0;
}
